package van.planifolia.work;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/11/2 18:03
 */
public class CallableCreateThread {
    public static void main(String[] args) {
        // 创建一个Callable的实现类然后交给FutureTask包装一下
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            System.out.println("123");
            return 123;
        });
        // 将futureTask交给Thread执行，然后通过futureTask中的get方法取到返回值并且打印
        new Thread(futureTask).start();
        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
}
